class Solution {
    int _target;
    vector<int> path;
    vector<vector<int>> ret;
 
public:
    vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
        _target = target;
        dfs(candidates, 0, 0);
        return ret;
    }
 
    void dfs(vector<int>& candidates, int pos, int sum)
    {
        if(sum > _target)
            return;
        if(sum == _target)
        {
            ret.push_back(path);
            return;
        }
 
        for(int i = pos; i < candidates.size(); ++i)
        {
            path.push_back(candidates[i]);
            dfs(candidates, i, sum + candidates[i]);
            path.pop_back();
        }
    }
};